package com.dqhl.business.view;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.PopupWindow;

import com.dqhl.business.R;
import com.dqhl.business.adapter.GoodsClassItemAdapter;
import com.dqhl.business.adapter.OrderPopWindowItemAdapter;
import com.dqhl.business.modle.GoodsClass;

import java.util.List;

/**
 * description:订单顶部状态
 * autour: guanluocang
 * date: 2016/11/3 16:01
 */
public class GoodsClassPopupWindow extends PopupWindow implements AdapterView.OnItemClickListener {

    private Context context;
    private List<GoodsClass> goodsClassList;
    private ListView lv_item;
    private GoodsClassItemAdapter goodsClassItemAdapter;
    private IOnItemSelectListener iOnItemSelectListener;

    public GoodsClassPopupWindow(Context context, List<GoodsClass> goodsClassList,
                                 IOnItemSelectListener iOnItemSelectListener) {
        super(context);
        this.context = context;
        this.goodsClassList = goodsClassList;
        this.iOnItemSelectListener = iOnItemSelectListener;

        initView();
    }

    private void initView() {
        View view = LayoutInflater.from(context).inflate(
                R.layout.order_popupwindow_spinner, null);
        setContentView(view);
        setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
        setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

        setFocusable(true);
        ColorDrawable dw = new ColorDrawable(0x00);
        setBackgroundDrawable(dw);

        lv_item = (ListView) view.findViewById(R.id.lv_item);
        goodsClassItemAdapter = new GoodsClassItemAdapter(context, goodsClassList);
        lv_item.setAdapter(goodsClassItemAdapter);
        lv_item.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        dismiss();
        if (iOnItemSelectListener != null) {
            iOnItemSelectListener.onItemClick(position);
        }
    }

    public interface IOnItemSelectListener {
        void onItemClick(int position);
    }
}
